﻿using Enough.Helper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace Enough.Converter
{
    public class TranslationConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (parameter == null)
            {
                return value;
            }
            string key = parameter.ToString();
            string translation = GlobalizationHelper.Localize(key + value);
            if (string.IsNullOrEmpty(translation))
            {
                translation = GlobalizationHelper.Localize(key);
            }
            if (string.IsNullOrEmpty(translation))
            {
                translation = key;
            }
            else
            {
                translation = string.Format(translation, value);
            }
            return translation;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
